package hot100;

public class Solution230 {
    int topK = 0;
    public int kthSmallest(TreeNode root, int k) {
        dfs(root, k);
        return topK;
    }

    private void dfs(TreeNode node, int k) {
        if (node == null) {
            return;
        }
        dfs(node.left, k);
        if (k == 0) {
            topK = node.val;
        }
        dfs(node.right, k - 1);
    }
}
